<?php

namespace App\Console\Commands;

use App\Models\MessagesTemplate;
use Illuminate\Console\Command;

class InitMsgTrigger extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'trigger:init';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '初始化群发模板';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $triggers = config('jinbell.trigger');
        foreach ($triggers as $key => $value) {
            $msgModel = MessagesTemplate::where('title',$value)->where('type',2)->first();
            if (empty($msgModel)) {
                $msgModel  = new MessagesTemplate();
                $msgModel->title = $value;
                $msgModel->messages = '';
                $msgModel->type = 2;
                $msgModel->save();
            }
        }
    }
}
